#include("/front/teacher/_layout.html")
#@layout()
#define layoutImportcss()
#end
#define layoutHead()
	<title>发布</title>
#end
#define layoutHome()


<div class="page-content hide-navbar-on-scroll message-page-content">
	<div class="navbar">
		<div class="navbar-inner toolbstyle">
			<div class="left">
				<a id="a_back" class="link external back" href="javascript:history.back()">
					<i class="icon icon-back"></i>
				</a>
			</div>
			<div class="title" id="navbar_title">发布</div>
			<div class="right">
				<a id="btn_a_save" class="button buttonw font-color-yellow" href="javascript:;">提交</a>
			</div>
		</div>
	</div>
	
<form id="my-form">
	<input type="hidden" id="note_id" name="note_id">
	<input type="hidden" id="type_id" name="type_id">
	
	<h1 id="note_title_lab" class="h1-title">请输入通知名称</h1>
	<input type="hidden" id="note_title" name="note_title" title="标题">
		
	<div class="message-content">
		
		<div class="card">
			<div id="note_desc_lab" class="card-content card-content-padding">
				请输入通知内容
			</div>
			<textarea id="note_desc" name="note_desc" title="内容" style="width:0px; height: 0px;"></textarea>
		</div>

		<div class="card" id="activity_exp_card" style="display: none;">
			<div class="list inline-labels no-hairlines-md">
				<ul>
					<li class="item-content item-input">
					  <div class="item-inner">
						<div class="item-title item-label">开始时间</div>
						<div class="item-input-wrap">
						  <input name="start_time" type="datetime-local" placeholder="Please choose...">
						</div>
					  </div>
					</li>
					<li class="item-content item-input">
					  <div class="item-inner">
						<div class="item-title item-label">结束时间</div>
						<div class="item-input-wrap">
						  <input name="end_time" type="datetime-local" placeholder="Please choose...">
						</div>
					  </div>
					</li>
					<li class="item-content item-input">
					  <div class="item-inner">
						<div class="item-input-wrap">
						  <input name="show_address" type="text" placeholder="活动地址">
						  <span class="input-clear-button"></span>
						</div>
					  </div>
					</li>
				</ul>
			</div>
		</div>

		<div class="card" id="note_pics_card" style="display: none;">
			<i class="f7-icons close">close</i>
			<div class="add-picture">
				<ul id="note_pics_lab">
				</ul>
			</div>
			<input type="hidden" id="note_pics" name="note_pics">
		</div>

		<div class="card" id="node_videos_card" style="display: none;">
			<i class="f7-icons close">close</i>
			<div id="node_videos" class="video-box">
				<div class="video" id="node_videos_lab"></div>
			</div>
			<input type="hidden" id="node_videos" name="node_videos">
		</div>

		<div class="block add-btn-group">
			<a id="btn_add_words" href="javascript:;" class="external" style="display: none;">
				<i class="f7-icons">circle_fill</i>
				<div>添加内容</div>
			</a>
			<a id="btn_add_pics" href="#" class="">
				<i class="f7-icons">circle_fill</i>
				<div>添加图片</div>
			</a>
			<a id="btn_add_videos" href="#" class="" style="display: none;">
				<i class="f7-icons">circle_fill</i>
				<div>添加视频</div>
			</a>
			<div style="display: none;">
			<input id="file_image" type="file" accept="image/*" multiple style="width:0px;height: 0px;">
			<input id="file_video" type="file" accept="video/*" multiple style="width:0px;height: 0px;">
			</div>
		</div>
	</div>
</form>
</div>
<div class="popup popup-edit-words">
    <div class="block">
		<div class="row">
			<div class="col-33">
				<a class="link popup-close" href="#">取消</a>
			</div>
			<div class="col-33" style="text-align: center;" id="popup_title">编辑文字</div>
			<div class="col-33" style="text-align: right;">
				<a id="popup_btn_ok" href="#">确定</a>
			</div>
		</div>
      <p>
		  <textarea id="popup_text" rows="20" style="width:100%; height: 90%; border: 1px solid #ccc;"></textarea>
		  <input id="popup_target" type="hidden">
	  </p>
    </div>
</div>
#end
#define layoutImportjs()
#end
#define layoutScript()
<script type="text/javascript">
	var typeid = getUrlParam('typeid');
	var type_name = "发布通知";
	if (typeid == 2){ 
		type_name = "发布活动"; 
		$$('#note_title_lab').html('请输入活动名称');
		$$('#note_desc_lab').html('请输入活动内容');
		$$('#activity_exp_card').show(); 
	}
	$$('#navbar_title').text(type_name);
	$$('#type_id').val(typeid);
	
	/**内容编辑**/
	$$('#note_title_lab').on("click", function(){
		showPopupText('note_title');
	});
	
	$$('#note_desc_lab').on("click", function(){
		showPopupText('note_desc');
	});
	$$('#btn_add_words').on("click", function(){
		showPopupText('note_desc');
	});
	
	function showPopupText(val_id){
		var val_txt = $$('#'+val_id).val();
		var val_title = $$('#'+val_id).attr('title');
		$$('#popup_target').val(val_id);
		$$('#popup_text').val(val_txt);
		$$('#popup_title').text('编辑'+val_title);
		
		app.popup.open($$('div.popup-edit-words'));
		$$('#popup_text').focus();
	}
	
	$$('#popup_btn_ok').on('click', function(){
		var val_id = $$('#popup_target').val();
		var val_txt = $$('#popup_text').val();
		$$('#'+val_id).val(val_txt);
		if (val_id=='note_desc'){
			val_txt=val_txt.replace('\r\n','<br>').replace('\n','<br>')
		}
		$$('#'+val_id+'_lab').html(val_txt);
		
		app.popup.close($$('div.popup-edit-words'));
	});
	
	/**图片上传**/
	$$('#btn_add_pics').on('click', function(){ $$("#file_image").click() });
	
	$$("#file_image").on("change", function(e){
		var sval = $$('#note_pics').val();
		var arry1 = trim(sval, ';').split(';');
		if (arry1.length >= 20){
			return false;
		}
		var file = e.target.files[0],
        reader = new FileReader();
		reader.readAsDataURL(file);
		reader.onload = function (ev) {
			if (checkUploadFile(file, 'images')){
				photo = ev.target.result //获取图片内容：base64字符串
				var formdata = { filename: file.name, 
								 filesize: file.size, 
								 filetype: '.'+file.type.split("/")[1], 
								 base64_data: photo };
								 
				sendPost('/front/teacher/fileup/upload_base64', formdata, function(res){
					//console.log(res);
					if (res.code == 0){
						var html ='<li><img src="'+getZoomFileUrl(res.fileurl)+'"></li>';
						$$('#note_pics_lab').prepend(html);
						
						sval += res.fileurl + ';';
						$$('#note_pics').val(sval);
						$$('#note_pics_card').show();
					}else{
						alert(res.msg);
					}
				});
			}
		};
	});
	/**视频上传**/
	$$('#btn_add_videos').on('click', function(){ $$("#file_video").click() });
	
	$$("#file_video").on("change", function(e){
		var sval = $$('#note_videos').val();
		var arry1 = trim(sval, ';').split(';');
		if (arry1.length >= 20){
			return false;
		}
		var file = e.target.files[0],
	    reader = new FileReader();
		reader.readAsDataURL(file);
		reader.onload = function (ev) {
			if (checkUploadFile(file, 'videos')){
				photo = ev.target.result //获取图片内容：base64字符串
				var formdata = { filename: file.name, 
								 filesize: file.size, 
								 filetype: '.'+file.type.split("/")[1], 
								 base64_data: photo };
								 
				sendPost('/front/teacher/fileup/upload_base64', formdata, function(res){
					//console.log(res);
					if (res.code == 0){
						var html ='<video src="'+res.fileurl+'"></video>';
						$$('#note_videos_lab').html(html);
						
						//sval += res.fileurl + ';';
						$$('#note_videos').val(res.fileurl);
						$$('#note_videos_card').show();
					}else{
						alert(res.msg);
					}
				});
			}
		};
	});
	
	/*保存*/
	$$('#btn_a_save').on('click', function(){
		if (validateForm('#my-form')){
		  var formData = app.form.convertToData('#my-form');
		  
		  //console.log(JSON.stringify(formData));

		   // 调用接口提交数据
		  var url = "/front/teacher/notes/save";
		  app.request({
			  url: url,
			  method: "POST",
			  dataType: "json", // 返回数据类型，可以是 json
			  data: formData,
			  success: function(res, status){
					alert(res.msg);
				  if(res.code == 200){
					  window.location.href = '/front/teacher/html/notes';
				  }
			  },
			  error: function(xhr, status){
				  alert(status);
			  }
		  });
		}
		return false;
	});
</script>
#end